package semantic_compute.relation_extraction.corenlp_extraction;

import edu.stanford.nlp.ie.machinereading.structure.MachineReadingAnnotations;
import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.ling.IndexedWord;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.semgraph.SemanticGraph;
import edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations;
import edu.stanford.nlp.semgraph.SemanticGraphEdge;
import edu.stanford.nlp.trees.GrammaticalRelation;
import edu.stanford.nlp.util.CoreMap;
import scala.reflect.internal.SymbolTableStats;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Properties;

/**
 * Created by julianzliu on 4/22/2017.
 */
public class CorenlpRelationExtraction {




    public static void test_relation_extraction(String inputText ){

        Properties props = new Properties();


        /*
        https://stanfordnlp.github.io/CoreNLP/relation.html
         */


        props.put( "annotators", "tokenize, ssplit, pos, lemma, ner, regexner, parse, dcoref, relation" );
        StanfordCoreNLP pipeLine = new StanfordCoreNLP( props );

        Annotation document = new Annotation( inputText );
        //document.set( CoreAnnotations.DocDateAnnotation.class, currentTime );

        // Finally we use the pipeline to annotate the document we created
        pipeLine.annotate( document );

        pipeLine.prettyPrint( document, System.out);

        System.out.println("\n\n GET Relation Extraction \n\n");

        System.out.println( (document.get(MachineReadingAnnotations.AllRelationMentionsAnnotation.class)).toString() );



    }


    /*****************************************************
     *
     * @param args
     */

    public static void main(String[] args){
        String text = "president who was born in Hawaii.";


        if(args.length > 0){
            text = "";
            for(String arg:args) text += " " + arg;
        }

        test_relation_extraction( text );

    }


}
